package com.shop.loan.model;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;
import xyz.erupt.annotation.Erupt;
import xyz.erupt.annotation.EruptField;
import xyz.erupt.annotation.sub_field.Edit;
import xyz.erupt.annotation.sub_field.EditType;
import xyz.erupt.annotation.sub_field.View;
import xyz.erupt.annotation.sub_field.sub_edit.AttachmentType;
import xyz.erupt.upms.model.base.HyperModel;

import javax.persistence.*;
import java.math.BigDecimal;

@Erupt(
        name = "商品规格",
        authVerify = false
)
@Table(name = "s_goods_size")
@Entity
@Getter
@Setter
@ApiModel("商品规格")
public class GoodsSize extends HyperModel {


    @Column(name = "goods_id")
    private Long goodsId;

    @EruptField(
            views = @View(title = "图片"),
            edit = @Edit(title = "图片", type = EditType.ATTACHMENT,
                    attachmentType = @AttachmentType(
                            type = AttachmentType.Type.IMAGE,
                            maxLimit = 1
                    )
            )
    )
    @ApiModelProperty(name = "pic", value = "图片（单张）", dataType = "string", example = "1")
    private String pic;

    @Transient //由于该字段不需要持久化，所以使用该注解修饰
    @EruptField(
            edit = @Edit(title = "-", type = EditType.DIVIDE)
    )
    private String divide4;

    @EruptField(
            views = @View(title = "规格名称"),
            edit = @Edit(
                    title = "规格名称",
                    notNull = true,
                    placeHolder = "请输入规格名称")
    )
    @ApiModelProperty(name = "memory", value = "内存", dataType = "string", example = "1")
    private String memory;


    @EruptField(
            views = @View(title = "价格"),
            edit = @Edit(title = "价格", notNull = true, placeHolder = "请输入价格")
    )
    @ApiModelProperty(name = "price", value = "官网价格", dataType = "string", example = "1")
    private BigDecimal price;


    @ManyToOne
    @EruptField(
            views = @View(title = "借款产品", column = "name", width = "100px"),
            edit = @Edit(
                    title = "借款产品",
                    type = EditType.REFERENCE_TREE
            )
    )
    @JoinColumn(name = "product_id")
    private Product product;


    @EruptField(
            views = @View(title = "要求结清订单数"),
            edit = @Edit(
                    title = "要求结清订单数",
                    notNull = true
            )
    )
    private Integer conditionNumber = 0;

    @EruptField(
            views = @View(title = "库存"),
            edit = @Edit(title = "库存", notNull = true, placeHolder = "请输入库存数量")
    )
    @ApiModelProperty(name = "stock", value = "库存", dataType = "string", example = "1")
    private Integer stock;


    @EruptField(
            views = @View(title = "已售数量"),
            edit = @Edit(title = "已售数量", notNull = true, placeHolder = "请输入已售数量")
    )
    @ApiModelProperty(name = "rentalStock", value = "已售数量", dataType = "string", example = "1")
    private Integer rentalStock = 0;

}
